package com.example.myapplication.ui.adapter

import android.os.Build
import android.text.TextUtils
import androidx.annotation.RequiresApi
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.myapplication.R
import com.example.myapplication.bean.coins.CoinInfoBean

/**
 *排行榜的adapter
 *
 * @author : Kun
 * @date : 2021/6/11
 * @time : 11:09
 */
class RankAdapter(layoutResId: Int, mList: ArrayList<CoinInfoBean>?) :
    BaseQuickAdapter<CoinInfoBean, BaseViewHolder>(layoutResId, mList), LoadMoreModule {

    @RequiresApi(Build.VERSION_CODES.M)
    override fun convert(holder: BaseViewHolder, item: CoinInfoBean) {
        holder.setText(R.id.tv_rank, "" + item.rank)
            .setText(
                R.id.tv_userName,
                if (TextUtils.isEmpty(item.nickname)) item.username else item.nickname
            )
            .setText(R.id.tv_coins, "积分：" + item.coinCount)
            .setText(R.id.tv_level, "等级：" + item.level)

        holder.setTextColor(
            R.id.tv_rank, context.getColor(
                when (item.rank) {
                    1 -> R.color.c_ffcc33
                    2 -> R.color.c_99ffff
                    3 -> R.color.c_ff9933
                    else -> R.color.c_999999
                }
            )
        )
    }
}